ARG BUILD_TIME=""
ARG GIT_COMMIT=""
ARG GO_VERSION=""

# Build
FROM golang:1.16-alpine as builder

# RUN apk add --no-cache gcc musl-dev linux-headers git make
RUN apk add --no-cache make gcc musl-dev linux-headers g++ llvm bash cmake git gmp-dev openssl-dev
RUN mkdir -p $GOPATH/src/github.com/PlatONnetwork && \
    cd $GOPATH/src/github.com/PlatONnetwork && \
    git clone https://github.com/PlatONnetwork/PlatON-Go.git --recursive --depth 1 && \
    cd PlatON-Go && go mod tidy && make platon

ADD . /go-service
RUN cd /go-service && \
    go mod edit -replace github.com/PlatONnetwork/PlatON-Go=$GOPATH/src/github.com/PlatONnetwork/PlatON-Go && \
    go mod tidy && \
    make monitor-linux

# Pull alpine container
FROM gcr.io/google.com/cloudsdktool/cloud-sdk:alpine

RUN apk --update add --no-cache ca-certificates libstdc++ bash tzdata gmp-dev openjdk7-jre
RUN gcloud components install app-engine-java kubectl
COPY --from=builder /go-service/build/bin/platon-tools-monitor-linux-amd64 /usr/local/bin/
COPY --from=builder /go-service/gcloud_sh/chain-node-poc-platon /usr/local/bin/chain-node-poc-platon
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

EXPOSE 13144
ENTRYPOINT ["platon-tools-monitor-linux-amd64"]